package by.bsu.touragency.command.client;

import org.apache.log4j.Logger;

import by.bsu.touragency.db.beans.InformationClient;
import by.bsu.touragency.db.beans.Person;
import by.bsu.touragency.db.dao.InformationClientDAO;
import by.bsu.touragency.db.dao.PersonDAO;


public class SetUserInfoLogic {

	private static Logger logger=Logger.getLogger("log");
	
	public static boolean isValid(String fio, String passport, String email,
			String telephone, String user) {
		PersonDAO cd = new PersonDAO();
		Person c = new Person();
		c=cd.readByLogin(user);
		
		InformationClientDAO icd = new InformationClientDAO();
		InformationClient ic = new InformationClient();
		ic.setClientId(c.getId());
		System.out.println("clientid"+ic.getClientId());
		ic = icd.readByClientID(c.getId());
		System.out.println("id"+c.getId());
		System.out.println("clientid"+ic.getClientId());
		
		if (ic.isValidFIO(fio)&&c.validityCheckEmail(email)&&ic.isValidPassport(passport)&&ic.isValidTel(telephone)){
			ic.setFIO(fio);
			ic.setPassport(passport);
			ic.setTel(telephone);
			ic.setClientId(c.getId());
			
			icd.update(ic);
			
			c.setEmail(email);
			
			cd.updateEmail(c);
			logger.debug("Valid data");
			return true;
		}
		logger.warn("Invalid FIO or email or passport or telephone");
		return false;
	}


}
